package org.kabeja.dxf.helpers;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author shutao
 * @since 2022/4/24 17:25
 */
public class TextDocument {
    protected List<Object> paragraphs = new ArrayList<>();

    public TextDocument() {
    }

    public String getText() {
        Iterator<?> var1 = this.paragraphs.iterator();
        StringBuilder var2 = new StringBuilder();

        while(var1.hasNext()) {
            StyledTextParagraph var3 = (StyledTextParagraph)var1.next();
            var2.append(var3.getText());
            if (var3.isNewline()) {
                var2.append('\n');
            }
        }

        return var2.toString();
    }

    public void addStyledParagraph(StyledTextParagraph var1) {
        this.paragraphs.add(var1);
    }

    public Iterator<?> getStyledParagraphIterator() {
        return this.paragraphs.iterator();
    }

    public int getParagraphCount() {
        return this.paragraphs.size();
    }

    public StyledTextParagraph getStyleTextParagraph(int var1) {
        return (StyledTextParagraph)this.paragraphs.get(var1);
    }

    public int getLineCount() {
        int var1 = 1;

        for (Object paragraph : this.paragraphs) {
            StyledTextParagraph var3 = (StyledTextParagraph) paragraph;
            if (var3.isNewline()) {
                ++var1;
            }
        }

        return var1;
    }

    public int getMaximumLineLength() {
        int var1 = 0;
        int var2 = 0;

        for (Object paragraph : this.paragraphs) {
            StyledTextParagraph var4 = (StyledTextParagraph) paragraph;
            if (!var4.isNewline()) {
                var1 += var4.getLength();
            } else {
                if (var1 > var2) {
                    var2 = var1;
                }

                var1 = var4.getLength();
            }
        }

        return var2;
    }
}
